import router from '@/router'
import store from '@/store'

const whiteList = ['/login', '/404']
router.beforeEach(async(to, form, next) => {
// 判断
  const { token } = store.getters
  if (token) {
    // 调用，跳转对应的页面之前调用
    await store.dispatch('user/getUserInfo')
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})
